#include "stdafx.h"
#include "KeyID.h"

namespace KeyID{
	typedef boost::bimap<wstring, UINT> KeyIDMap;
	
	KeyIDMap& GetKeyIDMap(){
		static KeyIDMap keyids;
		return keyids;
	}

	UINT GetID(wstring key){
		boost::to_lower(key);
		static UINT cmdID = 10000;
		UINT id = 0;
		KeyIDMap::left_const_iterator it = GetKeyIDMap().left.find(key);
		if(it != GetKeyIDMap().left.end()){
			id = it->second;
		}else{
			id = ++cmdID;
			GetKeyIDMap().insert(KeyIDMap::value_type(key, id));
		}
		return id;
	}
	wstring GetKey(UINT id){
		KeyIDMap::right_const_iterator it = GetKeyIDMap().right.find(id);
		if(it != GetKeyIDMap().right.end()){
			return it->second;
		}
		return L"";
	}
};